package com.jiemeng.sensordatawritesample;

import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity implements SensorEventListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        SensorDataRecorder.getInstance().init();
    }

    @Override
    protected void onDestroy() {
        SensorDataRecorder.getInstance().dispose();
        super.onDestroy();
    }

    @Override
    public void onSensorChanged(SensorEvent event) {
        if (event.sensor.getId() == SensorDataRecorder.SENSOR_TYPE_1) {
            SensorDataRecorder.getInstance().publishData(new SensorDataRecorder.SensorData(SensorDataRecorder.SENSOR_TYPE_1, Integer.toString(event.accuracy)));
        }
    }

    @Override
    public void onAccuracyChanged(Sensor sensor, int accuracy) {

    }
}